package com.zry.yard.ui.activity

import com.zry.yard.R
import com.zry.yard.adapter.AptitudeInfoAdapter
import com.zry.yard.animation.RecyclerViewUtilKt
import com.zry.yard.been.CustomerDetail
import com.zry.yard.been.CustomerInfo
import com.zry.yard.been.FilePath
import com.zry.yard.been.ResultBean
import com.zry.yard.databinding.ActivityDistributorInfoBinding
import com.zry.yard.retrofit.HttpServer
import com.zry.yard.retrofit.ShowUserView
import com.zry.yard.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_distributor_info.*
import kotlinx.android.synthetic.main.common_title.*

class DistributorInfoActivity : BaseActivity(), ShowUserView {

    private var customerInfo: CustomerInfo? = null
    private var distributorInfoBinding: ActivityDistributorInfoBinding? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_distributor_info
    }

    override fun initData() {

        titleCenterText.text = "经销商详情"
        commonLeftLinearLayout.setOnClickListener { finish() }
        customerInfo = intent.getSerializableExtra("CustomerInfo") as CustomerInfo
        distributorInfoBinding = viewDataBinding as ActivityDistributorInfoBinding

        HttpServer(this).getCustomerInfo(customerInfo!!.CustomerID, this)

        initRecycler()
    }

    fun initRecycler() {
        recyclerViewUtilKt = RecyclerViewUtilKt(this, aptitudeInfoRecycler)
        recyclerViewUtilKt?.initTableRecyclerView(4, 10)
    }


    private fun initAdapter(dataList: MutableList<FilePath>) {
        val aptitudeInfoAdapter = AptitudeInfoAdapter(this,R.layout.item_aptitude_info, dataList)
        recyclerViewUtilKt?.setAdapter(aptitudeInfoAdapter)
    }

    override fun toMainActivity(what: Int, data: Any) {
        when (what) {
            37 -> {
                val resultData = data as ResultBean<CustomerDetail>
                if (resultData.State == "1") {
                    distributorInfoBinding?.customerDetail = resultData.ResultData
                    initAdapter(resultData.ResultData.dataList)
                } else {
                    toast(resultData.Message)
                }
            }
        }
    }
}
